const app = getApp();
Page({
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    name: "",
    mobilePhone: "",
    idCard: ""
  },
  onLoad() {
    
  }
  ,//用户触发获取用户信息
  getUserInfo: function (e) {
    var detail = e.detail;
    //用户拒绝授权时
    if (detail.errMsg != "getUserInfo:ok") {
      // this.getUserInfoAuthAgain();
      return;
    }
    wx.showLoading({
      title: '请稍后...',
      mask: true
    });
    var sessionId = app.globalData.sessionId;
    var that = this;
    var param = {
      sessionKey: sessionId,
      signature: detail.signature,
      rawData: detail.rawData,
      encryptedData: detail.encryptedData,
      iv: detail.iv
    };
    wx.request({
      url: app.url.updateUserInfo,
      method: "POST",
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: param,
      success: function (res) {
        wx.hideLoading();
        that.setData({
          hasUserInfo: true
        });
        app.globalData.userInfo = res.data.data;
        app.globalData.loginState = true;
        wx.navigateBack({
          delta: 1
        });
      },
      fail: res => {
        wx.hideLoading();
        wx.showModal({
          content: '更新用户信息出错',
          showCancel: false,
          success: function (res) { }
        });
      }
    });
  }
})